package com.jiajia.study.chapter04;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.*;

public class FutureTest {

    private static final Logger log = LoggerFactory.getLogger(FutureTest.class);

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        testJdkFuture();
    }

    private static void testJdkFuture() throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newSingleThreadExecutor();

        Future<Integer> submit = executorService.submit(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                log.debug("执行了......");
                Thread.sleep(10000);
                return 10;
            }
        });
        // 阻塞等待结果，只能通过同步等待拿到结果
        Integer result = submit.get();

        // 执行完成了
        log.debug("执行完成了，拿到的结果是：" + result);


    }
}
